package com.weasel.weixin.mp;

import com.weasel.helper.ClassPathFileReader;
import com.weasel.weixin.commons.service.CustomerServiceListResponse;
import com.weasel.weixin.commons.service.CustomerServiceRequest;
import com.weasel.weixin.commons.service.CustomerServiceResponse;
import com.weasel.weixin.commons.service.bean.CustomService;
import com.weasel.weixin.mp.builder.MpConfigBuilder;
import com.weasel.weixin.mp.config.MpConfig;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**客服帐号管理测试
 * 运行main方法，通过注释和打开注释来测试各方法
 * Created by Dylan on 2015/10/16.
 */
public class CustomServiceDemo {

    public static MpConfig config = null;
    public static CustomerServiceRequest request = null;
    static {

        try {
            config = MpConfigBuilder.fromXML("classpath:weixin-config.xml");
            request = new CustomerServiceRequest(config);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String [] args) throws IOException, ExecutionException {

      //  add();
      //  update();
      //  delete();
      //  uploadHeadImg();
        list();
    }

    public static void add() throws IOException, ExecutionException {

        CustomService service = new CustomService();
        service.setAccount("linhy2011@126.com");
        service.setNickName("张三");
        service.setPassword("123");

        CustomerServiceResponse response = request.add(service);

        System.out.print(response);
    }

    public static void update() throws IOException, ExecutionException {

        CustomService service = new CustomService();
        service.setAccount("zhangshang");
        service.setNickName("张三");
        service.setPassword("456");

        CustomerServiceResponse response = request.update(service);

        System.out.print(response);
    }

    public static void delete() throws IOException, ExecutionException {

        CustomService service = new CustomService();
        service.setAccount("zhangshang");
        service.setNickName("张三");
        service.setPassword("456");

        CustomerServiceResponse response = request.delete(service);

        System.out.print(response);
    }

    public static void uploadHeadImg() throws ExecutionException {

        File img = new File(ClassPathFileReader.getClassPath()+"\\"+"52.jpg");
        CustomerServiceResponse response = request.uploadHeadImg("zhangshang", img);
        System.out.print(response);
    }

    public static void list() throws IOException, ExecutionException {

        CustomerServiceListResponse response = request.getList();

        System.out.print(response);
    }
}
